/**
  ******************************************************************************
  * @file    User/user.c
  * @author  JUSHENG Application Team
  * @version V1.0.4
  * @date    02-19-2022
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 JUSHENG</center></h2>
  *
  *
  ******************************************************************************
  */ 

/* Includes ------------------------------------------------------------------*/
#include "include.h"
#include "user.h"
#include "tk_cfg.h"

u8 flash_data[8] __attribute__((aligned(4)));
u32 eflash_addr = EFLASH_DATA_SEC_INDEX * LL_EF_SECTOR_SIZE;
u8 need_lvd = 0;
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
void para_init(void)
{
    TYPE_LL_EFLASH_INIT eflash_init;
    ll_eflash_init(EFLASH, &eflash_init);
    need_lvd = 1;
    NVIC_InitTypeDef nvic;
    nvic.NVIC_IRQChannel = LVD_IRQn;
    nvic.NVIC_IRQChannelPriority = 0;
    nvic.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&nvic);
}

void lvd_init(void)
{
    SYSCTRL_REG_OPT(
    LVD->LVD_CON &= ~(LL_LVD_CON_LVD_DIG_EN);
    LVD->LVD_CON =  (LVD->LVD_CON & ~(LL_LVD_CON_VDD_DBS_LO_LIMIT(ALL_BYTE_FF))) | LL_LVD_CON_VDD_DBS_LO_LIMIT(10);
    LVD->LVD_CON =  (LVD->LVD_CON & ~(LL_LVD_CON_VDD_DBS_HI_LIMIT(ALL_BYTE_FF))) | LL_LVD_CON_VDD_DBS_HI_LIMIT(10);
    LVD->LVD_CON1 =  (LVD->LVD_CON1 & ~(LL_LVD_CON1_VCC_DBS_LO_LIMIT(ALL_BYTE_FF))) | LL_LVD_CON1_VCC_DBS_LO_LIMIT(10);
    LVD->LVD_CON1 =  (LVD->LVD_CON1 & ~(LL_LVD_CON1_VCC_DBS_HI_LIMIT(ALL_BYTE_FF))) | LL_LVD_CON1_VCC_DBS_HI_LIMIT(10);
    LVD->LVD_CON =  (LVD->LVD_CON & ~(LL_LVD_CON_VCC_LVD_SET(ALL_BYTE_FF))) | LL_LVD_CON_VCC_LVD_SET(LL_LVD_VCC_LVD_SET_3_6);
    LVD->LVD_CON &= ~(LL_LVD_CON_VCC_RST_EN);
    LVD->LVD_CON |= (LL_LVD_CON_VCC_LVD_EN| LL_LVD_CON_VDD_LVD_EN | LL_LVD_CON_VDD_RST_EN | LL_LVD_CON_LVD_DIG_EN);
    LL_LVD_VCC_PENDING_CLR(LVD);
    LL_LVD_VDD_PENDING_CLR(LVD);
    )
    
    NVIC_InitTypeDef nvic;
    nvic.NVIC_IRQChannel = LVD_IRQn;
    nvic.NVIC_IRQChannelPriority = 0;
    nvic.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&nvic);
}

void lvd_handle(void)
{
    u32 i = 0;
    u32 *pBuf = NULL;
  
    for(i = 0; i < (sizeof(flash_data)); i += 4)
    {
        *pBuf++ = LL_EFLASH_DATA_GET(eflash_addr + i);
    }
}


/**
  * @}
  */

/*************************** (C) COPYRIGHT 2022 JUSHENG ***** END OF FILE *****/
